using SuperSocket.Server;
using System;
using System.Threading.Tasks;

namespace JT808Gateway.Core
{
    /// <summary>
    /// JT808部标设备会话管理
    /// </summary>
    public class JT808Session : AppSession
    {
        /// <summary>
        /// 会话对应的Sim号码
        /// </summary>
        public string SimNumber { get; set; }

        protected override ValueTask OnSessionClosedAsync(EventArgs e)
        {
            //Todo:设备掉线时操作
            SessionManager.Instance.RemoveSession(this);
            return base.OnSessionClosedAsync(e);
        }

        protected override ValueTask OnSessionConnectedAsync()
        {
            //Todo:设备上线时操作
            SessionManager.Instance.AddSession(this);
            return base.OnSessionConnectedAsync();
        }

        /// <summary>
        /// 向管道发送消息
        /// </summary>
        /// <param name="sendBytes">消息字节数组</param>
        /// <returns></returns>
        public async Task SendMsg(byte[] sendBytes)
        {
            await Channel.SendAsync(sendBytes);
        }
    }
}